def fun(nums):
    result=[]
    path=[]
    used=[False]*len(nums)
    def backtracking(nums,used):
        if len(nums)==len(path):
            result.append(path[:])
            return
        for i in range(len(nums)):
            if not used[i]:
                if i>0 and not used[i-1] and nums[i]==nums[i-1]:
                    continue
                used[i]=True
                path.append(nums[i])
                backtracking(nums,used)
                used[i]=False
                path.pop()
    backtracking(nums,used)
    return result
res=fun([1,1,2])
print(res)